<?php
include_once '../meihe/common.php';
if ($islogin2 == 1) {
} else exit("<script language='javascript'>window.location.href='./login.php';</script>");
$title = '用户端控制台';
include './header.php';
if ($userrow['power'] == 2) {
    $type = '0,2';
} else if ($userrow['power'] == 1) {
    $type = '0,1';
} else {
    $type = '0,1,2';
}
$hyyum = $DB->count("SELECT count(*) from meihe_list WHERE 1 and upzid='{$userrow['zid']}'");
$scjl = $DB->count("SELECT count(*) from meihe_report WHERE 1 and upzid='{$userrow['zid']}'");
$wdgd = $DB->count("SELECT count(*) FROM meihe_workorder WHERE zid='{$userrow['zid']}'");
$msgcount = $DB->count("SELECT count(*) FROM meihe_message WHERE type IN ($type) AND active=1");
$msgread = explode(',', $userrow['msgread'] ?? '');
$rs = $DB->query("SELECT * FROM meihe_message WHERE type IN ($type) AND active=1 ORDER BY id DESC LIMIT 10");
$msgrow = array();
while ($res = $DB->fetch($rs)) {
    if (in_array($res['id'], $msgread)) $res['read'] = true;
    else $res['read'] = false;
    $msgrow[] = $res;
}
?>
<style>
    .console-user-group {
        position: relative;
        padding: 10px 0 10px 60px;
    }

    .console-user-group .console-user-group-head {
        width: 32px;
        height: 32px;
        position: absolute;
        top: 50%;
        left: 12px;
        margin-top: -16px;
        border-radius: 50%;
    }

    .console-user-group .layui-badge {
        position: absolute;
        top: 50%;
        right: 8px;
        margin-top: -10px;
    }

    .console-user-group .console-user-group-name {
        line-height: 1.2;
    }

    .console-user-group .console-user-group-desc {
        color: #8c8c8c;
        line-height: 1;
        font-size: 12px;
        margin-top: 5px;
    }
</style>
<link rel="stylesheet" href="//lib.baomitu.com/toastr.js/latest/css/toastr.min.css">
<div class="row">
    <div class="col-xl-4">
        <div class="card d-block pt-2 pb-1 text-center">
            <img class="card-img-top m-auto" style="height: 68px;width: 68px;margin:auto;display: block;border-radius: 0.3em;box-shadow: 0px 0px 30px #ccc" src="//q4.qlogo.cn/headimg_dl?dst_uin=<?= $userrow['qq'] ?>&spec=640" alt="Card image cap">
            <div class="card-body pb-2">
                <h5 class="card-title">UID:<?php echo $userrow['zid'] ?></h5>
                <p class="card-text text-success"><?php echo qqname($userrow['qq']) ?> [ <?php echo ($userrow['power'] == 2 ? '<font class="layui-btn layui-btn-xs layui-btn-normal" color=red>贵族用户</font>' : '<font class="layui-btn layui-btn-xs layui-btn-primary" color=red>普通用户</font>') ?> ]</p>
            </div>
            <a class="btn btn-outline-info mb-2" href="generate.php?mod=scurl"><i class="layui-icon layui-icon-link"></i> 生成链接</a>
            <a class="btn btn-outline-warning mb-2" href="uset.php?mod=account"><i class="layui-icon layui-icon-user"></i> 个人中心</a>
            <?php if ($userrow['power'] == 1) { ?>
                <a class="btn btn-outline-primary mb-2" href="upsite.php"><i class="layui-icon layui-icon-upload"></i> 升级权限</a>
            <?php }
            if ($userrow['power'] == 2) { ?>
                <a class="btn btn-outline-primary mb-2" href="viphy.php"><i class="layui-icon layui-icon-list"></i> 会员列表</a>
            <?php } ?>
            <a class="btn btn-outline-danger mb-2" href="generate.php"><i class="layui-icon layui-icon-list"></i> 生成记录</a>
            <a class="btn btn-outline-secondary mb-2" href="uset.php?mod=account"><i class="layui-icon layui-icon-list"></i> KEY密钥</a>
            <a class="btn btn-outline-primary mb-2" href="qiandao.php"><i class="layui-icon layui-icon-ok-circle"></i> 每日签到</a>
            <?php if ($userrow['power'] == 2) { ?>
                <a class="btn btn-outline-success mb-2" href="viphy.php?my=add"><i class="layui-icon layui-icon-auz"></i> 添加会员</a>
            <?php }
            if ($userrow['power'] == 1) { ?>
                <a class="btn btn-outline-success mb-2" href="uset.php?mod=viphy"><i class="layui-icon layui-icon-cart"></i> 购买会员</a>
            <?php } ?>
            <a class="btn btn-outline-success mb-2" href="workorder.php"><i class="layui-icon layui-icon-survey"></i> 工单管理</a>
            <a class="btn btn-outline-secondary mb-2" href="recharge.php"><i class="layui-icon layui-icon-rmb"></i> 在线充值</a>
            <hr>
            <?php
            foreach ($msgrow as $row) {
                echo '' . ($row['read'] ? '
                    <div class="console-user-group">
                        <img src="http://q4.qlogo.cn/headimg_dl?dst_uin=' . $conf['kfqq'] . '&amp;spec=100" class="console-user-group-head" alt="站长" lay-tips="站长QQ: ' . $conf['kfqq'] . '"/> 
                        <div class="console-user-group-name"><a class="badge ' . ($row['read'] ? '' : 'warning') . '" onclick="ckgg(' . $row['id'] . ')">' . $row['title'] . '</a></div>
                        <div class="console-user-group-desc"><a class="badge ' . ($row['read'] ? '' : 'warning') . '" onclick="ckgg(' . $row['id'] . ')">查看消息</a></div>
                        <span class="layui-badge layui-badge-red" lay-tips="您已经阅读过此公告！">已读</span>
                    </div>
                    ' : '
                    <div class="console-user-group">
                        <img src="http://q4.qlogo.cn/headimg_dl?dst_uin=' . $conf['kfqq'] . '&amp;spec=100" class="console-user-group-head" alt="站长" lay-tips="站长QQ: ' . $conf['kfqq'] . '"/> 
                        <div class="console-user-group-name"><a class="badge ' . ($row['read'] ? '' : 'warning') . '" onclick="ckgg(' . $row['id'] . ')">' . $row['title'] . '</a></div>
                        <div class="console-user-group-desc"><a class="badge ' . ($row['read'] ? '' : 'warning') . '" onclick="ckgg(' . $row['id'] . ')">查看消息</a></div>
                        <span class="layui-badge layui-badge-green" lay-tips="您还没有查看此公告！">未读</span>
                    </div>
                    ') . '';
            }
            if ($msgcount == 0) {
                echo '<center>站长还没有通知消息~ </br></center>';
            }
            ?>
            <?php if ($userrow['power'] == 2) { ?>
                <tr>
                    <td style="width:50px"><b>账号到期时间：</td>
                    <td></b><?php echo $userrow['endtime'] ?></font> <a href="renew.php" class="layui-btn layui-btn-xs layui-btn-normal">立即续期</a></td>
                </tr><?php } ?>
        </div> <!-- end card-->
    </div>
    <div class="col-xl-8">
        <div class="row">
            <div class="col-xl-6">
                <div class="row">
                    <div class="col-lg-6 col-md-6 col-sm-6 col-xl-6" style="width: 50%;">
                        <div class="card widget-flat">
                            <div class="card-body">
                                <div class="float-right" style="width: 30px;height: 30px">
                                    <a href="javascript:;" onclick="layer.tips('累计会员统计', this, {tips: 1});"> <i class="layui-icon layui-icon-list widget-icon" style="background-color: #ff0a24;color: white;"></i>
                                </div>
                                <h5 class="text-muted font-weight-normal mt-0">我的会员 </h5>
                                <h5 class="mt-2 mb-0" style="font-weight: 300"><?php echo $hyyum; ?> 个</h5></a>
                            </div> <!-- end card-body-->
                        </div> <!-- end card-->
                    </div> <!-- end col-->
                    <div class="col-lg-6 col-md-6 col-sm-6 col-xl-6" style="width: 50%">
                        <div class="card widget-flat">
                            <div class="card-body">
                                <div class="float-right" style="width: 30px;height: 30px">
                                    <a href="javascript:;" onclick="layer.tips('生成记录统计', this, {tips: 1});"> <i class="layui-icon layui-icon-list widget-icon" style="background-color: #ff824d;color: white"></i>
                                </div>
                                <h5 class="text-muted font-weight-normal mt-0">我的生成</h5>
                                <h5 class="mt-2 mb-0" style="font-weight: 300"><?php echo $scjl; ?> 条</h5>
                            </div> <!-- end card-body-->
                        </div> <!-- end card-->
                    </div> <!-- end col-->
                </div>
            </div>
            <div class="col-xl-6">
                <div class="row">
                    <div class="col-lg-6 col-md-6 col-sm-6 col-xl-6" style="width: 50%;">
                        <div class="card widget-flat">
                            <div class="card-body">
                                <div class="float-right" style="width: 30px;height: 30px">
                                    <a href="javascript:;" onclick="layer.tips('钱包统计', this, {tips: 1});"> <i class="layui-icon layui-icon-rmb widget-icon" style="background-color: #ff6ba8;color: white;"></i>
                                </div>
                                <h5 class="text-muted font-weight-normal mt-0">我的余额 </h5>
                                <h5 class="mt-2 mb-0" style="font-weight: 300"><?= $userrow['rmb'] ?> 元</h5></a>
                            </div> <!-- end card-body-->
                        </div> <!-- end card-->
                    </div> <!-- end col-->
                    <div class="col-lg-6 col-md-6 col-sm-6 col-xl-6" style="width: 50%;">
                        <div class="card widget-flat">
                            <div class="card-body">
                                <div class="float-right" style="width: 30px;height: 30px">
                                    <a href="javascript:;" onclick="layer.tips('工单统计', this, {tips: 1});"> <i class="layui-icon layui-icon-survey widget-icon" style="background-color: #FF7043;color: white;"></i>
                                </div>
                                <h5 class="text-muted font-weight-normal mt-0">我的工单 </h5>
                                <h5 class="mt-2 mb-0" style="font-weight: 300"><?php echo $wdgd; ?> 个</h5></a>
                            </div> <!-- end card-body-->
                        </div> <!-- end card-->
                    </div> <!-- end col-->
                </div>
            </div>
            <div class="col-xl-6">
                <div class="card">
                    <div class="card-header">
                        站长管理公告
                    </div>
                    <div class="card-body">
                        <?php if (empty($conf['gg_panel'])) {
                            echo '站长还未发布网站公告！';
                        } else {
                            echo '' . $conf['gg_panel'] . '';
                        } ?>
                    </div>
                </div>
            </div>

        </div> <!-- end row -->
    </div>
</div>
<?php
include_once './bottom.php';
?>
<script src="../assets/layuiadmin/layui/layui.js"></script>
<script src="//cdn.staticfile.org/layer/2.3/layer.js"></script>
<script>
    function ckgg(id) {
        $.ajax({
            type: 'GET',
            url: 'ajax.php?act=msginfo&id=' + id,
            dataType: 'json',
            success: function(data) {
                if (data.code == 0) {
                    layer.open({
                        type: 1,
                        title: '查看公告通知',
                        skin: 'layui-layer-admin',
                        area: '350px',
                        anim: 5,
                        shadeClose: true,
                        content: '<div class="widget"><div class="widget-content widget-content-mini themed-background-muted text-center"><b>' + data.title + '</b><br/><small><font color="grey">管理员  ' + data.date + '</font></small></div><div class="widget-content">' + data.content + '</div></div>',
                        end: function() {
                            window.location.reload()
                        }
                    });
                } else {
                    layer.alert(data.msg);
                }
            },
            error: function(data) {
                layer.msg('服务器错误');
                return false;
            }
        });
    }
</script>
<script src="//lib.baomitu.com/toastr.js/latest/toastr.min.js"></script>